package com.cn.xiaonuo.tcrfinance.tcrbanner.controller;

import com.cn.xiaonuo.common.entity.BusinessMessage;
import com.cn.xiaonuo.common.utils.ApiJsonModel;
import com.cn.xiaonuo.common.utils.GetJavaTypeConvert;

import com.cn.xiaonuo.tcrfinance.tcrbanner.param.BannerParam;
import com.cn.xiaonuo.tcrfinance.tcrbanner.service.PvBannerService;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
public class PvBannerController {

    @Resource
    private PvBannerService pvBannerService;

    @ApiOperation(value = "首页查看Banner", notes = "首页查看Banner")
    @ApiJsonModel({
            @ApiModelProperty(name = "types", value = "类型:1.首页轮播2.首页入口3.首页促销4.首页视频", example = "类型:1.首页轮播2.首页入口3.首页促销4.首页视频（true）", required = true)
    })
    @RequestMapping(value = "/api/banner/queryBanners", method = RequestMethod.POST)
    public BusinessMessage queryBanners(@RequestBody Map<String, Object> params) {
        Integer type = GetJavaTypeConvert.getInteger(params.get("types"));
        return pvBannerService.queryBanners(type);
    }

    //管理系统banner列表
    @ApiOperation(value = "管理系统banner列表", notes = "管理系统banner列表")
    @ApiJsonModel({
            @ApiModelProperty(name = "pageSize", value = "页码",example = "页码"),
            @ApiModelProperty(name = "pageNo", value = "每页多少数量",example = "每页多少数量")
    })
    @RequestMapping(value = "/api/banner/selectBanners", method = RequestMethod.POST)
    public BusinessMessage selectBanners(@RequestBody Map<String, Object> params) {
        Integer pageSize = GetJavaTypeConvert.getInteger(params.get("pageSize"));
        Integer pageNum = GetJavaTypeConvert.getInteger(params.get("pageNum"));
        BusinessMessage message = pvBannerService.selectBanners(pageSize, pageNum);
        return message;
    }

    //管理系统添加banner
    @ApiOperation(value = "管理系统添加banner", notes = "管理系统添加banner")
    @ApiJsonModel({
            @ApiModelProperty(name = "title", value = "标题",example = "标题（true）",required = true),
            @ApiModelProperty(name = "imageUrl", value = "banner图地址", example = "banner图地址（true）",required = true),
            @ApiModelProperty(name = "actionSort", value = " 排序默认值100，降序",example = " 排序默认值100，降序",required = true),
            @ApiModelProperty(name = "type", value = "类型:导航类型：1首页轮播图，2首页入口，3首页促销活动，4首页视频，5首页销售模式，6首页直播，20官网首页banner图",
                    example = "类型:导航类型：1首页轮播图，2首页入口，3首页促销活动，4首页视频，5首页销售模式，6首页直播，20官网首页banner图（true）",required = true),
            @ApiModelProperty(name = "cmdAndroid", value = " 跳转页面",example = " 跳转页面",required = false),
            @ApiModelProperty(name = "cmdParameter", value = " 跳转商品页代表商品id，跳转店铺页代表店铺id",example = " 跳转商品页代表商品id，跳转店铺页代表店铺id",required = false),
    })
    @RequestMapping(value = "/api/banner/insertBanner", method = RequestMethod.POST)
    public BusinessMessage insertBanner(@RequestBody Map<String, Object> params) {
        String title = GetJavaTypeConvert.getString(params.get("title"));
        String imageUrl = GetJavaTypeConvert.getString(params.get("imageUrl"));
        String actionSort = GetJavaTypeConvert.getString(params.get("actionSort"));
        String type = GetJavaTypeConvert.getString(params.get("type"));
        String cmdAndroid=GetJavaTypeConvert.getString(params.get("cmdAndroid"));
        String cmdParameter=GetJavaTypeConvert.getString(params.get("cmdParameter"));
        BusinessMessage message = pvBannerService.insertBanner(title, imageUrl, actionSort, type,cmdAndroid,cmdParameter);
        return message;
    }

    //管理系统删除banner
    @ApiOperation(value = "管理系统删除banner", notes = "管理系统删除banner")
    @ApiJsonModel({
            @ApiModelProperty(name = "id", value = "id",example = "id（true）",required = true)
    })
    @RequestMapping(value = "/api/banner/deleteBanner", method = RequestMethod.POST)
    public BusinessMessage deleteBanner(@RequestBody Map<String, Object> params) {
        Integer id = GetJavaTypeConvert.getInteger(params.get("id"));
        BusinessMessage message = pvBannerService.deleteBanner(id);
        return message;
    }

    //管理系统修改banner
    @ApiOperation(value = "管理系统查看banner", notes = "管理系统查看banner")
    @RequestMapping(value = "/api/banner/queryBannerById", method = RequestMethod.POST)
    public BusinessMessage queryBannerById(@RequestBody BannerParam bannerParam) {

        BusinessMessage message = pvBannerService.queryBannerById(bannerParam);
        return message;
    }

    //管理系统修改banner
    @ApiOperation(value = "管理系统修改banner", notes = "管理系统修改banner")
    @RequestMapping(value = "/api/banner/updateBanner", method = RequestMethod.POST)
    public BusinessMessage updateBanner(@RequestBody BannerParam bannerParam) {

        BusinessMessage message = pvBannerService.updateBanner(bannerParam);
        return message;
    }
}
